﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CodeBuilderForVS2022
{
    public partial class LoadingForm : Form
    {
        /// <summary>
        /// 是否完成
        /// </summary>
        public bool IsFinished { get; set; }

        /// <summary>
        /// 最大步骤
        /// </summary>
        public int MaxCount { get; set; } = 16;

        public LoadingForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 改变加载状态
        /// </summary>
        /// <param name="log">日志</param>
        /// <param name="num">第几部</param>
        public void ShowLoading(string log, int num)
        {
            if (num == -1)
            {
                txt_log.Text = log;
                txt_process.Visible = false;
                IsFinished = true;
            }
            else
            {
                IsFinished = false;
                txt_log.Text = log;
                txt_process.Visible = true;
                txt_process.Text = $"{num} / {MaxCount}";
            }

        }

        /// <summary>
        /// 生成异常
        /// </summary>
        /// <param name="log">日志</param>
        public void ShowError(string log)
        {
            txt_log.Text = log;
            lable_loading.Visible = false;
            lbl_error.Visible = true;
            IsFinished = false;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("https://flyadmin.top");
        }

        /// <summary>
        /// 关闭生成窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoadingForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //加载完成之后，或者异常才允许关闭
            if (IsFinished || lbl_error.Visible)
            {
                e.Cancel = false;
            }
            else
            {
                e.Cancel = true;
            }
        }
    }
}
